package com.jpxx.netty.heartBeat;

import io.netty.handler.codec.marshalling.DefaultMarshallerProvider;
import io.netty.handler.codec.marshalling.DefaultUnmarshallerProvider;
import io.netty.handler.codec.marshalling.MarshallerProvider;
import io.netty.handler.codec.marshalling.MarshallingDecoder;
import io.netty.handler.codec.marshalling.MarshallingEncoder;
import io.netty.handler.codec.marshalling.UnmarshallerProvider;

import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;


//MarshallingCodeCFactory  格式固定
public class MarshallingCodeCFactory {
	 public static MarshallingDecoder buildMarshallingDecoder() {    
	        final MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");    
	        final MarshallingConfiguration configuration = new MarshallingConfiguration();    
	        configuration.setVersion(5);    
	        UnmarshallerProvider provider = new DefaultUnmarshallerProvider(factory, configuration);    
	        MarshallingDecoder decoder = new MarshallingDecoder(provider, 1024*1024*1);//可以容忍序列化的最大程度，1个G
	        return decoder;    
	    }    
	    
	    public static MarshallingEncoder buildMarshallingEncoder() {    
	        final MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");    
	        final MarshallingConfiguration configuration = new MarshallingConfiguration();    
	        configuration.setVersion(5);    
	        MarshallerProvider provider = new DefaultMarshallerProvider(factory, configuration);    
	        MarshallingEncoder encoder = new MarshallingEncoder(provider);    
	        return encoder;    
	    }    
}
